// SocketTestFrame.h : interface of the CSocketTestFrame class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once
#include "INetCallback.h"

struct ISocketManager;

struct CurProcess
{
	int				iAddr;
	int				iPort;
	DWORD			dwStart;
	time_t			t;
	ISocketManager*	pManager;
};

class CSocketTestFrame : 
	public CFrameWindowImpl<CSocketTestFrame>, 
	public CUpdateUI<CSocketTestFrame>,
	public CAppWindow<CSocketTestFrame>,
	public CMessageFilter, public CIdleHandler,
	public INetCallback
{
public:
	DECLARE_APP_FRAME_CLASS(NULL, IDR_MAINFRAME, L"Software\\WTL\\SocketTest")

	CSocketTestView m_view;

	virtual BOOL PreTranslateMessage(MSG* pMsg);

// CAppWindow operations
	bool AppHibernate( bool bHibernate);

	bool AppNewInstance( LPCTSTR lpstrCmdLine);

	void AppSave();

#ifdef WIN32_PLATFORM_WFSP
	void AppBackKey();
#endif

	virtual BOOL OnIdle();

	BEGIN_UPDATE_UI_MAP(CSocketTestFrame)
	END_UPDATE_UI_MAP()

	BEGIN_MSG_MAP(CSocketTestFrame)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
		COMMAND_ID_HANDLER(ID_ACTION, OnAction)
		COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
		MESSAGE_HANDLER(WM_CLOSE, OnClose)
		COMMAND_ID_HANDLER(ID_FILE_SAVE, OnFileSave)
		MESSAGE_HANDLER(WM_TIMER, OnTimer)
		CHAIN_MSG_MAP(CAppWindow<CSocketTestFrame>)
		CHAIN_MSG_MAP(CUpdateUI<CSocketTestFrame>)
		CHAIN_MSG_MAP(CFrameWindowImpl<CSocketTestFrame>)
	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

	LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	LRESULT OnAction(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	virtual WORD OnReceive(const BYTE* pData, WORD wLen);
	virtual void OnSend();
	virtual void OnConnected();
	virtual void OnError(int iErrCode);

	LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnFileSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

private:
	void ExecuteOne();
	void MoveNext();
	void ShowOne(LPCTSTR lpszResult);
	CurProcess m_CurProc;
public:
	LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
};
